import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import App from './App.vue'
import VueI18n from 'vue-i18n'
import locales from  './zh.js'
import VueRouter from 'vue-router'
import VueResource  from 'vue-resource';

Vue.use(VueI18n);
Vue.use(ElementUI);
Vue.use(VueRouter);
Vue.use(VueResource);

Vue.http.options.root = '/root';
Vue.http.headers.common['apikey'] = '694167ba7fb6be7086cc0ca568547be1';

const routes = [
    {
        path: '/new/list/',
        component: function (resolve) {
            require(['./components/New/list.vue'], resolve)
        }
    },
    {
        path: '/new/add/',
        component: function (resolve) {
            require(['./components/New/add.vue'], resolve)
        }
    },
    {
        path: '/new/:id/change/',
        name:'new_change',
        component: function (resolve) {
            require(['./components/New/change.vue'], resolve)
        }
    },
    {
        path: '/auth/login/',
        component: function (resolve) {
            require(['./components/Auth/login.vue'], resolve)
        }
    },
    {
        path: '*',
        redirect: '/new/list/'
    }
];

const router = new VueRouter({
    routes // （缩写）相当于 routes: routes
});
window.router = router;

// set lang
Vue.config.lang = 'zh';

// set locales
Object.keys(locales).forEach(function (lang) {
    Vue.locale(lang, locales[lang])
});

new Vue({
    el: '#app',
    router,
    render: h => h(App)
});